package com.zzyl.service.impl;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.entity.NursingProject;
import com.zzyl.entity.ProjectPlans;
import com.zzyl.mapper.NursingMapper;
import com.zzyl.service.NursingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class NursingServiceImpl implements NursingService {

    @Autowired
    private NursingMapper nursingMapper;
    @Override
    public PageResponse<NursingProject> list(String name, Integer pageNum, Integer pageSize, Integer status) {
        PageResponse<NursingProject> pageResponse = new PageResponse<>();
        PageHelper.startPage(pageNum, pageSize);
        Page<NursingProject> page = nursingMapper.list(name, status);
        pageResponse.setRecords(page);
        pageResponse.setTotal(page.getTotal());
        pageResponse.setPages((long) page.getPages());
        pageResponse.setPage(page.getPageNum());
        return pageResponse;
    }

    @Override
    public void add(NursingProject nursingProject) {
        nursingProject.setCreateTime(LocalDateTime.now());
        nursingProject.setUpdateTime(LocalDateTime.now());
        nursingProject.setCreateBy(2L);
        nursingMapper.addProject(nursingProject);
    }

    @Override
    public NursingProject getById(Long id) {
        NursingProject nursingProject = nursingMapper.getById(id);
        return nursingProject;
    }

    @Override
    public void updateById(NursingProject nursingProject) {
        nursingProject.setUpdateTime(LocalDateTime.now());
        nursingMapper.updateById(nursingProject);
    }

    @Override
    public void deleteById(Long id) {
        nursingMapper.deleteById(id);
    }

    @Override
    public void disableById(Long id, Integer status) {
        nursingMapper.disableById(id, status);
    }

    @Override
    public List<NursingProject> listAll() {
        List<NursingProject> list = nursingMapper.listAll();
        return list;
    }

    @Override
    public Integer deleteBeforeSelect(Long id) {
        Integer cnt = nursingMapper.deleteBeforeSelect(id);
        return cnt;
    }
}
